package com.hee.erp.modules.controller;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hee.erp.common.R;
import com.hee.erp.modules.entity.SysDictType;
import com.hee.erp.modules.entity.SysDictValue;
import com.hee.erp.modules.entity.SysJob;
import com.hee.erp.modules.service.ISysDictTypeService;
import com.hee.erp.modules.service.ISysDictValueService;
import com.hee.erp.modules.service.ISysJobService;
import com.hee.erp.vo.JobListPageParamsVo;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author weizehong
 * @since 2022-03-22
 */
@RestController
@RequestMapping("/modules/sysJob")
public class SysJobController {

    @Autowired
    ISysJobService targetService;

    //四个方法 listByPage,getDetailById,delById,save

    @PostMapping("/listByPage")
    @ApiOperation(value = "listByPage",notes = "{\n" +
            "\"current\":1,\n" +
            "\"pageSize\":10\n" +
            "}")
    public R<IPage<SysJob>> listByPage(@RequestBody JobListPageParamsVo vo){
        IPage<SysJob> page = targetService.listByPage(vo);
        return R.success(page);
    }

    @ApiOperation(value = "getById")
    @GetMapping("/getById")
    public R<SysJob> getById(String id){
        SysJob entity = targetService.getDetailById(id);
        return R.success(entity);
    }

    @PostMapping("/save")
    @ApiOperation(value = "save")
    public R<Boolean> save(@RequestBody SysJob entity){
        if(StringUtils.isBlank(entity.getId())){
            entity.setPublishDate(LocalDate.now());
        }
        targetService.saveOrUpdate(entity);

        return R.success(true);
    }

    @ApiOperation("delById")
    @GetMapping("/delById")
    public R<Boolean> delById(String id){
        targetService.removeById(id);
        return R.success(true);
    }

}

